package edu.washington.cs.workflow.analysis.guistructure;

import edu.washington.cs.workflow.util.Utils;

public abstract class UIAbstractEntity implements EventEntity {
	
	public final String methodDesc;
	public final long timestamp;
	public final int thizObjHash;
	public final boolean isEntry;
	
	public UIAbstractEntity(String methodDesc, Object obj, boolean entryOrExit /*true is entry*/) {
		this(methodDesc, System.identityHashCode(obj), entryOrExit, System.currentTimeMillis());
	}
	
	UIAbstractEntity(String methodDesc, int hashCode, boolean entryOrExit /*true is entry*/, long timestamp) {
		Utils.checkNotNull(methodDesc);
		this.methodDesc = methodDesc;
		this.timestamp = timestamp;
		this.thizObjHash = hashCode;
		this.isEntry = entryOrExit;
	}
	
	protected String strContent() {
		return //this.getClass().getName() + " : " + 
		      this.methodDesc + EventEntity.SEP
		    + this.isEntry + EventEntity.SEP
		    + this.thizObjHash + EventEntity.SEP
		    + this.timestamp;
	}
	
	@Override
	public int hashCode() {
		return this.methodDesc.hashCode()
		    + 13* this.thizObjHash
//		    + 17*this.timestamp
		    + 29*(this.isEntry ? 17 : 13);
	}
	
	public boolean equals(Object o) {
		if(!(o instanceof UIAbstractEntity)) {
			return false;
		}
		UIAbstractEntity that = (UIAbstractEntity)o;
		return this.methodDesc.equals(that.methodDesc)
		    && this.thizObjHash == that.thizObjHash
//		    && this.timestamp == that.timestamp
		    && this.isEntry == that.isEntry;
	}
	
}
